<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>webchannel.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="local_closure_goog_labs_net_webchannel.js.html">webchannel.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2013 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> * @fileoverview The API spec for the WebChannel messaging library.
<a name="line17"></a> *
<a name="line18"></a> * Similar to HTML5 WebSocket and Closure BrowserChannel, WebChannel
<a name="line19"></a> * offers an abstraction for point-to-point socket-like communication between
<a name="line20"></a> * a browser client and a remote origin.
<a name="line21"></a> *
<a name="line22"></a> * WebChannels are created via &lt;code&gt;WebChannel&lt;/code&gt;. Multiple WebChannels
<a name="line23"></a> * may be multiplexed over the same WebChannelTransport, which represents
<a name="line24"></a> * the underlying physical connectivity over standard wire protocols
<a name="line25"></a> * such as HTTP and SPDY.
<a name="line26"></a> *
<a name="line27"></a> * A WebChannels in turn represents a logical communication channel between
<a name="line28"></a> * the client and server end point. A WebChannel remains open for
<a name="line29"></a> * as long as the client or server end-point allows.
<a name="line30"></a> *
<a name="line31"></a> * Messages may be delivered in-order or out-of-order, reliably or unreliably
<a name="line32"></a> * over the same WebChannel. Message delivery guarantees of a WebChannel is
<a name="line33"></a> * to be specified by the application code; and the choice of the
<a name="line34"></a> * underlying wire protocols is completely transparent to the API users.
<a name="line35"></a> *
<a name="line36"></a> * Client-to-client messaging via WebRTC based transport may also be support
<a name="line37"></a> * via the same WebChannel API in future.
<a name="line38"></a> *
<a name="line39"></a> */
<a name="line40"></a>
<a name="line41"></a>goog.provide(&#39;goog.net.WebChannel&#39;);
<a name="line42"></a>
<a name="line43"></a>goog.require(&#39;goog.events&#39;);
<a name="line44"></a>goog.require(&#39;goog.events.Event&#39;);
<a name="line45"></a>
<a name="line46"></a>
<a name="line47"></a>
<a name="line48"></a>/**
<a name="line49"></a> * A WebChannel represents a logical bi-directional channel over which the
<a name="line50"></a> * client communicates with a remote server that holds the other endpoint
<a name="line51"></a> * of the channel. A WebChannel is always created in the context of a shared
<a name="line52"></a> * {@link WebChannelTransport} instance. It is up to the underlying client-side
<a name="line53"></a> * and server-side implementations to decide how or when multiplexing is
<a name="line54"></a> * to be enabled.
<a name="line55"></a> *
<a name="line56"></a> * @interface
<a name="line57"></a> * @extends {EventTarget}
<a name="line58"></a> */
<a name="line59"></a>goog.net.WebChannel = function() {};
<a name="line60"></a>
<a name="line61"></a>
<a name="line62"></a>/**
<a name="line63"></a> * Configuration spec for newly created WebChannel instances.
<a name="line64"></a> *
<a name="line65"></a> * WebChannels are configured in the context of the containing
<a name="line66"></a> * {@link WebChannelTransport}. The configuration parameters are specified
<a name="line67"></a> * when a new instance of WebChannel is created via {@link WebChannelTransport}.
<a name="line68"></a> *
<a name="line69"></a> * messageHeaders: custom headers to be added to every message sent to the
<a name="line70"></a> * server.
<a name="line71"></a> *
<a name="line72"></a> * messageUrlParams: custom url query parameters to be added to every message
<a name="line73"></a> * sent to the server.
<a name="line74"></a> *
<a name="line75"></a> * spdyRequestLimit: the maximum number of in-flight HTTP requests allowed
<a name="line76"></a> * when SPDY is enabled. Currently we only detect SPDY in Chrome.
<a name="line77"></a> * This parameter defaults to 10. When SPDY is not enabled, this parameter
<a name="line78"></a> * will have no effect.
<a name="line79"></a> *
<a name="line80"></a> * supportsCrossDomainXhr: setting this to true to allow the use of sub-domains
<a name="line81"></a> * (as configured by the server) to send XHRs with the CORS withCredentials
<a name="line82"></a> * bit set to true.
<a name="line83"></a> *
<a name="line84"></a> * testUrl: the test URL for detecting connectivity during the initial
<a name="line85"></a> * handshake. This parameter defaults to &quot;/&lt;channel_url&gt;/test&quot;.
<a name="line86"></a> *
<a name="line87"></a> *
<a name="line88"></a> * @typedef {{
<a name="line89"></a> *   messageHeaders: (!Object.&lt;string, string&gt;|undefined),
<a name="line90"></a> *   messageUrlParams: (!Object.&lt;string, string&gt;|undefined),
<a name="line91"></a> *   spdyRequestLimit: (number|undefined),
<a name="line92"></a> *   supportsCrossDomainXhr: (boolean|undefined),
<a name="line93"></a> *   testUrl: (string|undefined)
<a name="line94"></a> * }}
<a name="line95"></a> */
<a name="line96"></a>goog.net.WebChannel.Options;
<a name="line97"></a>
<a name="line98"></a>
<a name="line99"></a>/**
<a name="line100"></a> * Types that are allowed as message data.
<a name="line101"></a> *
<a name="line102"></a> * @typedef {(ArrayBuffer|Blob|Object.&lt;string, string&gt;|Array)}
<a name="line103"></a> */
<a name="line104"></a>goog.net.WebChannel.MessageData;
<a name="line105"></a>
<a name="line106"></a>
<a name="line107"></a>/**
<a name="line108"></a> * Open the WebChannel against the URI specified in the constructor.
<a name="line109"></a> */
<a name="line110"></a>goog.net.WebChannel.prototype.open = goog.abstractMethod;
<a name="line111"></a>
<a name="line112"></a>
<a name="line113"></a>/**
<a name="line114"></a> * Close the WebChannel.
<a name="line115"></a> */
<a name="line116"></a>goog.net.WebChannel.prototype.close = goog.abstractMethod;
<a name="line117"></a>
<a name="line118"></a>
<a name="line119"></a>/**
<a name="line120"></a> * Sends a message to the server that maintains the other end point of
<a name="line121"></a> * the WebChannel.
<a name="line122"></a> *
<a name="line123"></a> * @param {!goog.net.WebChannel.MessageData} message The message to send.
<a name="line124"></a> */
<a name="line125"></a>goog.net.WebChannel.prototype.send = goog.abstractMethod;
<a name="line126"></a>
<a name="line127"></a>
<a name="line128"></a>/**
<a name="line129"></a> * Common events fired by WebChannels.
<a name="line130"></a> * @enum {string}
<a name="line131"></a> */
<a name="line132"></a>goog.net.WebChannel.EventType = {
<a name="line133"></a>  /** Dispatched when the channel is opened. */
<a name="line134"></a>  OPEN: goog.events.getUniqueId(&#39;open&#39;),
<a name="line135"></a>
<a name="line136"></a>  /** Dispatched when the channel is closed. */
<a name="line137"></a>  CLOSE: goog.events.getUniqueId(&#39;close&#39;),
<a name="line138"></a>
<a name="line139"></a>  /** Dispatched when the channel is aborted due to errors. */
<a name="line140"></a>  ERROR: goog.events.getUniqueId(&#39;error&#39;),
<a name="line141"></a>
<a name="line142"></a>  /** Dispatched when the channel has received a new message. */
<a name="line143"></a>  MESSAGE: goog.events.getUniqueId(&#39;message&#39;)
<a name="line144"></a>};
<a name="line145"></a>
<a name="line146"></a>
<a name="line147"></a>
<a name="line148"></a>/**
<a name="line149"></a> * The event interface for the MESSAGE event.
<a name="line150"></a> *
<a name="line151"></a> * @constructor
<a name="line152"></a> * @extends {goog.events.Event}
<a name="line153"></a> */
<a name="line154"></a>goog.net.WebChannel.MessageEvent = function() {
<a name="line155"></a>  goog.net.WebChannel.MessageEvent.base(
<a name="line156"></a>      this, &#39;constructor&#39;, goog.net.WebChannel.EventType.MESSAGE);
<a name="line157"></a>};
<a name="line158"></a>goog.inherits(goog.net.WebChannel.MessageEvent, goog.events.Event);
<a name="line159"></a>
<a name="line160"></a>
<a name="line161"></a>/**
<a name="line162"></a> * The content of the message received from the server.
<a name="line163"></a> *
<a name="line164"></a> * @type {!goog.net.WebChannel.MessageData}
<a name="line165"></a> */
<a name="line166"></a>goog.net.WebChannel.MessageEvent.prototype.data;
<a name="line167"></a>
<a name="line168"></a>
<a name="line169"></a>/**
<a name="line170"></a> * WebChannel level error conditions.
<a name="line171"></a> * @enum {number}
<a name="line172"></a> */
<a name="line173"></a>goog.net.WebChannel.ErrorStatus = {
<a name="line174"></a>  /** No error has occurred. */
<a name="line175"></a>  OK: 0,
<a name="line176"></a>
<a name="line177"></a>  /** Communication to the server has failed. */
<a name="line178"></a>  NETWORK_ERROR: 1,
<a name="line179"></a>
<a name="line180"></a>  /** The server fails to accept the WebChannel. */
<a name="line181"></a>  SERVER_ERROR: 2
<a name="line182"></a>};
<a name="line183"></a>
<a name="line184"></a>
<a name="line185"></a>
<a name="line186"></a>/**
<a name="line187"></a> * The event interface for the ERROR event.
<a name="line188"></a> *
<a name="line189"></a> * @constructor
<a name="line190"></a> * @extends {goog.events.Event}
<a name="line191"></a> */
<a name="line192"></a>goog.net.WebChannel.ErrorEvent = function() {
<a name="line193"></a>  goog.net.WebChannel.ErrorEvent.base(
<a name="line194"></a>      this, &#39;constructor&#39;, goog.net.WebChannel.EventType.ERROR);
<a name="line195"></a>};
<a name="line196"></a>goog.inherits(goog.net.WebChannel.ErrorEvent, goog.events.Event);
<a name="line197"></a>
<a name="line198"></a>
<a name="line199"></a>/**
<a name="line200"></a> * The error status.
<a name="line201"></a> *
<a name="line202"></a> * @type {!goog.net.WebChannel.ErrorStatus}
<a name="line203"></a> */
<a name="line204"></a>goog.net.WebChannel.ErrorEvent.prototype.status;
<a name="line205"></a>
<a name="line206"></a>
<a name="line207"></a>/**
<a name="line208"></a> * @return {!goog.net.WebChannel.RuntimeProperties} The runtime properties
<a name="line209"></a> * of the WebChannel instance.
<a name="line210"></a> */
<a name="line211"></a>goog.net.WebChannel.prototype.getRuntimeProperties = goog.abstractMethod;
<a name="line212"></a>
<a name="line213"></a>
<a name="line214"></a>
<a name="line215"></a>/**
<a name="line216"></a> * The readonly runtime properties of the WebChannel instance.
<a name="line217"></a> *
<a name="line218"></a> * This class is defined for debugging and monitoring purposes, and for
<a name="line219"></a> * optimization functions that the application may choose to manage by itself.
<a name="line220"></a> *
<a name="line221"></a> * @interface
<a name="line222"></a> */
<a name="line223"></a>goog.net.WebChannel.RuntimeProperties = function() {};
<a name="line224"></a>
<a name="line225"></a>
<a name="line226"></a>/**
<a name="line227"></a> * @return {number} The effective request limit for the channel.
<a name="line228"></a> */
<a name="line229"></a>goog.net.WebChannel.RuntimeProperties.prototype.getSpdyRequestLimit =
<a name="line230"></a>    goog.abstractMethod;
<a name="line231"></a>
<a name="line232"></a>
<a name="line233"></a>/**
<a name="line234"></a> * This method may be used by the application to stop ack of received messages
<a name="line235"></a> * as a means of enabling or disabling flow-control on the server-side.
<a name="line236"></a> *
<a name="line237"></a> * @param {boolean} enabled If true, enable flow-control behavior on the
<a name="line238"></a> * server side. Setting it to false will cancel ay previous enabling action.
<a name="line239"></a> */
<a name="line240"></a>goog.net.WebChannel.RuntimeProperties.prototype.setServerFlowControl =
<a name="line241"></a>    goog.abstractMethod;
<a name="line242"></a>
<a name="line243"></a>
<a name="line244"></a>/**
<a name="line245"></a> * This method may be used by the application to throttle the rate of outgoing
<a name="line246"></a> * messages, as a means of sender initiated flow-control.
<a name="line247"></a> *
<a name="line248"></a> * @return {number} The total number of messages that have not received
<a name="line249"></a> * ack from the server and therefore remain in the buffer.
<a name="line250"></a> */
<a name="line251"></a>goog.net.WebChannel.RuntimeProperties.prototype.getNonAckedMessageCount =
<a name="line252"></a>    goog.abstractMethod;
</pre>


</body>
</html>
